package com.ewhale.feitengguest.presenter.user.message;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.dto.ConversationDto;
import com.ewhale.feitengguest.view.user.message.ChatConversationView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;

public class ChatConversationPresenter extends IPresenter {
    public void getConversionList(String keyWord) {
        mView.showProLoading();
        if (keyWord.isEmpty()) {
            request(1, ApiHelper.MESSAGE_API.getAccountMasterAndApprenticeList(), null);
        } else {
            request(2, ApiHelper.MESSAGE_API.getAccountMasterAndApprenticeList(keyWord), keyWord);
        }
    }

    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode) {
            case 1:
                ((ChatConversationView) mView).showConversationList((ConversationDto) result,"");
                break;
            case 2:
                ((ChatConversationView) mView).showConversationList((ConversationDto) result,(String)data);
                break;
        }
    }

    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode, e.getCode(), e.getDisplayMessage());
    }
}
